import { request } from "@umijs/max";

// /dev-api/ying/product-category/list

export async function getProductCategoryList(
  params: {
    // query
    /** 当前的页码 */
    pageNum?: number;
    /** 页面的容量 */
    pageSize?: number;
  },
  options?: { [key: string]: any }
) {
  return request<API.ProductCategoryList>(
    "/api/ying/product-category/level-list",
    {
      method: "GET",
      params: {
        ...params,
      },
      ...(options || {}),
    }
  );
}
//
// ​/dev-api​/ying​/product-category​/level-list
export async function getProductCategoryLevelList(
  params: {},
  options?: {
    [key: string]: any;
  }
) {
  return request<API.ProductCategoryList>(
    "/api/ying/product-category/level-list",
    {
      params: {
        ...params,
      },
      method: "GET",
      ...(options || {}),
    }
  );
}

// ​/dev-api​/ying​/product​/add
export async function addProduct(
  body: API.AddProductParams,
  options?: { [key: string]: any }
) {
  return request<API.BaseResponse>("/api/ying/product/add", {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
    },
    data: body,
    ...(options || {}),
  });
}
// /dev-api/ying/product-category/edit
export async function editCategory(
  body: any,
  options?: { [key: string]: any }
) {
  return request<API.BaseResponse>("/api/ying/product-category/edit", {
    method: "PUT",
    headers: {
      "Content-Type": "application/json",
    },
    data: body,
    ...(options || {}),
  });
}
// /dev-api/ying/product-category/add
export async function addCategory(body: any, options?: { [key: string]: any }) {
  return request<API.BaseResponse>("/api/ying/product-category/add", {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
    },
    data: body,
    ...(options || {}),
  });
}
// /dev-api/ying/product-category/delete/{id}
export async function deleteCategory(
  params: { id: number },
  options?: { [key: string]: any }
) {
  return request<API.BaseResponse>(
    `/api/ying/product-category/delete/${params.id}`,
    {
      method: "DELETE",
      ...(options || {}),
    }
  );
}
// /dev-api/ying/product/list
export async function getProductList(
  params: {
    // query
    /** 当前的页码 */
    pageNum?: number;
    /** 页面的容量 */
    pageSize?: number;
    productCategoryId: number | undefined;
  },
  options?: { [key: string]: any }
) {
  return request<API.ProductList>("/api/ying/product/list", {
    method: "GET",
    params: {
      ...params,
    },
    ...(options || {}),
  });
}
// /dev-api/ying/product/detail/{id}
export async function getProductDetail(
  params: { id: number },
  options?: { [key: string]: any }
) {
  return request<API.ProductDetail>(`/api/ying/product/detail/${params.id}`, {
    method: "GET",
    ...(options || {}),
  });
}
// /dev-api/ying/product/edit
export async function editProduct(
  body: API.EditProductParams,
  options?: { [key: string]: any }
) {
  return request<API.BaseResponse>("/api/ying/product/edit", {
    method: "PUT",
    headers: {
      "Content-Type": "application/json",
    },
    data: body,
    ...(options || {}),
  });
}
// /dev-api/ying/product/delete
export async function deleteProduct(
  body: { ids: number[] },
  options?: { [key: string]: any }
) {
  return request<API.BaseResponse>("/api/ying/product/delete", {
    method: "DELETE",
    headers: {
      "Content-Type": "application/json",
    },
    data: body,
    ...(options || {}),
  });
}
// /dev-api/ying/product/move PUT
export async function moveProduct(
  body: { ids: number[]; productCategoryId: number },
  options?: { [key: string]: any }
) {
  return request<API.BaseResponse>("/api/ying/product/move", {
    method: "PUT",
    headers: {
      "Content-Type": "application/json",
    },
    data: body,
    ...(options || {}),
  });
}

// /dev-api/ying/product/update-status

export async function updateProductStatus(
  body: { id: number; productStatus: number },
  options?: { [key: string]: any }
) {
  return request<API.BaseResponse>("/api/ying/product/update-status", {
    method: "PUT",
    headers: {
      "Content-Type": "application/json",
    },
    data: body,
    ...(options || {}),
  });
}
// /dev-api/ying/product/export
export async function exportProduct(
  body: { ids?: number[] },
  options?: { [key: string]: any }
) {
  return request<API.BaseResponse>("/api/ying/product/export", {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
    },
    data: body,
    ...(options || {}),
  });
}
// /dev-api/ying/product/importfile
export async function importProductFile(
  body: FormData,
  options?: { [key: string]: any }
) {
  return request<API.BaseResponse>("/api/ying/product/importfile", {
    method: "POST",
    headers: {
      "Content-Type": "multipart/form-data",
    },
    data: body,
    ...(options || {}),
  });
}
